/* eslint-disable */

import {
  REQ_CURRENT_USER,
  REC_CURRENT_USER,

  REQ_USERS_BY_EMAIL_GROUP,
  REC_USERS_BY_EMAIL_GROUP
} from '../util/constants';

import {handleActions} from 'redux-actions';
import * as update from 'react-addons-update';
import {createRequestReducer, createReceiveReducer, compose} from './helper';

export default handleActions({

  // 获取用户信息
  [REQ_CURRENT_USER]: createRequestReducer('fetching', 'current'),
  [REC_CURRENT_USER]: compose((state, action) => action.error ? state : update(state, {
    current: {
      data: {
        $set: action.payload.data
      }
    }
  }), createReceiveReducer('fetching', 'current')),

  ['UPDATE_USER_ACL']: (state, action) => update(state, {
    current: {
      data: {
        acl: {
          $set: action.payload
        }
      }
    }
  })

}, {

  // 当前用户
  current: {
    ctx: null,
    data: null,
    message: null,
    fetching: false,
    invalid: false,
    error: null
  }
});
